import { getObjLocal } from '@/assets/js/localStore'

export const shuffle = arr => {
  const newArr = arr.slice()
  const length = newArr.length
  for (let i = 0; i < length - 1; ++i) {
    const random = getRandom(length - i)
    swap(newArr, i, random)
  }
  return newArr
}

const getRandom = max => {
  return Math.floor(Math.random() * max) + 1
}

const swap = (arr, i, j) => {
  const temp = arr[i]
  arr[i] = arr[j]
  arr[j] = temp
}

export const loadFavouriteListFromLocal = () => {
  return getObjLocal('favourite')
}

export const formatTime = interval => {
  interval = Math.floor(interval)
  const minutes = (Math.floor(interval / 60) + '').padStart(2, '0')
  const seconds = (Math.floor(interval - minutes * 60) + '').padStart(2, '0')
  return `${minutes}:${seconds}`
}
